
package com.edu.marker.utils;


public class LogUtils {

    private final static int VERBOSE = 0x00;
    private final static int DEBUG = 0x01;
    private final static int INFO = 0x02;
    private final static int WARN = 0x03;
    private final static int ERROR = 0x04;

    private final static int DEFAULT_LEVEL;
    private static final String TAG = "LogUtils";

    static {
        DEFAULT_LEVEL = -1;
    }

    private final String clazz;

    private int level;

    /**
     * Gets the debug log.
     * 
     * @param clazz the clazz
     * @param l the l
     * @return the debug log
     */
    public static LogUtils getDebugLog(Class<?> clazz, int l) {
        LogUtils log = new LogUtils(clazz);
        log.level = l;
        return log;
    }

    /**
     * Gets the log.
     * 
     * @param clazz the clazz
     * @return the log
     */
    public static LogUtils getLog(Class<?> clazz) {
        return new LogUtils(clazz);
    }

    /**
     * Instantiates a new log utils.
     * 
     * @param clazz the clazz
     */
    public LogUtils(Class<?> clazz) {
        this.clazz = "[" + clazz.getSimpleName() + "] ";
        level = DEFAULT_LEVEL;
    }

    /**
     * Verbose.
     * 
     * @param message the message
     */
    public void v(String message) {
        verbose(message, null);
    }

    /**
     * Debug.
     * 
     * @param message the message
     */
    public void d(String message) {
        debug(message, null);
    }

    /**
     * Info.
     * 
     * @param message the message
     */
    public void i(String message) {
        info(message, null);
    }

    /**
     * Warn.
     * 
     * @param message the message
     */
    public void w(String message) {
        warn(message, null);
    }

    /**
     * Error.
     * 
     * @param message the message
     */
    public void e(String message) {
        error(message, null);
    }

    /**
     * Verbose.
     * 
     * @param message the message
     * @param t the t
     */
    public void verbose(String message, Throwable t) {
        if (VERBOSE < level) return;
        if (message != null) android.util.Log.v(TAG, clazz + " Line: " + getLineNumber() + " : " + message);
        if (t != null) android.util.Log.v(TAG, clazz + " Line: " + getLineNumber() + " : " + t.toString());
    }

    /**
     * Debug.
     * 
     * @param message the message
     * @param t the t
     */
    public void debug(String message, Throwable t) {
        if (DEBUG < level) return;
        if (message != null) android.util.Log.d(TAG, clazz + " Line: " + getLineNumber() + " : " + message);
        if (t != null) android.util.Log.d(TAG, clazz + " Line: " + getLineNumber() + " : " + t.toString());
    }

    /**
     * Info.
     * 
     * @param message the message
     * @param t the t
     */
    public void info(String message, Throwable t) {
        if (INFO < level) return;
        if (message != null) android.util.Log.i(TAG, clazz + " Line: " + getLineNumber() + " : " + message);
        if (t != null) android.util.Log.i(TAG, clazz + " Line: " + getLineNumber() + " : " + t.toString());
    }

    /**
     * Warn.
     * 
     * @param message the message
     * @param t the t
     */
    public void warn(String message, Throwable t) {
        if (WARN < level) return;
        if (message != null) android.util.Log.w(clazz, clazz + " Line: " + getLineNumber() + " : " + message);
        if (t != null) android.util.Log.w(clazz, clazz + " Line: " + getLineNumber() + " : " + t.toString());
    }

    /**
     * Error.
     * 
     * @param message the message
     * @param t the t
     */
    public void error(String message, Throwable t) {
        if (ERROR < level) return;
        if (message != null) android.util.Log.e(clazz, clazz + " Line: " + getLineNumber() + " : " + message);
        if (t != null) android.util.Log.e(clazz, clazz + " Line: " + getLineNumber() + " : " + t.toString());
    }

    /**
     * Gets the line number.
     * 
     * @return the line number
     */
    private static int getLineNumber() {
        return Thread.currentThread().getStackTrace()[5].getLineNumber();
    }
}
